//File: dynamic_array.h
//
//Modified by Pei Liu on 10/25/2011
//
//fuc add, get_used arraytrav
//

#ifndef DYNAMIC_ARRAY
#define DYNAMIC_ARRAY
#include "stdio.h"

/* d_array is an expandable array type holding either int or pointers */

typedef union
{
   int ival;
   void *pval;
} ptrint;

typedef struct
{
   ptrint *array;
   int current_size;   /* how many slots allocated */
   int used;           /* how many of the allocated slots in use */ 
} d_array;

/* store and retrieve have union, int, and pointer versions */

d_array *create_d_array();
int store(ptrint i, int index, d_array *p);
int store_int(int i, int index, d_array *p);
int store_ptr(void *ptr, int index, d_array *p);
ptrint retrieve(int index, d_array *p);
int retrieve_int(int index, d_array *p);
void *retrieve_ptr(int index, d_array *p);
int get_used(d_array* p);
void arraytrav(FILE* fout, d_array* p);

#endif
